﻿using IdentityModel;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace XxSystem.UsersServer.Controllers
{
    public class ApiController : ControllerBase
    {
        public long UserId
        {
            get
            {
                var id = User?.Claims?.FirstOrDefault(x => x.Type == ClaimTypes.NameIdentifier);
                long rs = 0;
                long.TryParse(id?.Value, out rs);
                return rs;
            }
        }
        public string UserName
        {
            get
            {
                return User?.Identity?.Name;
            }
        }
        public string NickName
        {
            get
            {
                var nickName = User?.Claims?.FirstOrDefault(x => x.Type == JwtClaimTypes.PreferredUserName);
                return nickName?.Value;
            }
        }
    }

}
